using Microsoft.SharePoint.WebControls;
using System.Web.Security;
using System.Web.UI.WebControls;
using System;

namespace CKS.FormsBasedAuthentication
{
    /// <summary>
    /// Code behind for UsersDisp.aspx
    /// </summary>
    public class FBASiteConfiguration : LayoutsPageBase
    {
        //Site locations
        protected InputFormTextBox txtChangePasswordPage;
        protected InputFormTextBox txtPasswordQuestionPage;
        protected InputFormTextBox txtThankYouPage;

        //XSLT locations
        protected InputFormTextBox txtMembershipApproved;
        protected InputFormTextBox txtMembershipError;
        protected InputFormTextBox txtMembershipPending;
        protected InputFormTextBox txtMembershipRejected;
        protected InputFormTextBox txtPasswordRecovery;


        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack)
            {
                /* bms Set the URL strings in the web properties */
                txtChangePasswordPage.Text = this.Web.Properties[MembershipReviewSiteURL.CHANGEPASSWORDPAGE];
                txtPasswordQuestionPage.Text = this.Web.Properties[MembershipReviewSiteURL.PASSWORDQUESTIONPAGE];
                txtThankYouPage.Text = this.Web.Properties[MembershipReviewSiteURL.THANKYOUPAGE];

                /* bms Set the XSLT location web properties */
                txtMembershipApproved.Text = this.Web.Properties[MembershipReviewSiteXSLTEmail.MEMBERSHIPAPPROVED];
                txtMembershipError.Text = this.Web.Properties[MembershipReviewSiteXSLTEmail.MEMBERSHIPERROR];
                txtMembershipPending.Text = this.Web.Properties[MembershipReviewSiteXSLTEmail.MEMBERSHIPPENDING];
                txtMembershipRejected.Text = this.Web.Properties[MembershipReviewSiteXSLTEmail.MEMBERSHIPREJECTED];
                txtPasswordRecovery.Text = this.Web.Properties[MembershipReviewSiteXSLTEmail.PASSWORDRECOVERY];
            }
        }

        protected void BtnUpdateSiteFBAConfig_Click(object sender, EventArgs e)
        {


            /* bms Set the URL strings in the web properties */
            UpdateProperty(MembershipReviewSiteURL.CHANGEPASSWORDPAGE, txtChangePasswordPage.Text);
            UpdateProperty(MembershipReviewSiteURL.PASSWORDQUESTIONPAGE,txtPasswordQuestionPage.Text);
            UpdateProperty(MembershipReviewSiteURL.THANKYOUPAGE,txtThankYouPage.Text);

            /* bms Set the XSLT location web properties */
            UpdateProperty(MembershipReviewSiteXSLTEmail.MEMBERSHIPAPPROVED,txtMembershipApproved.Text);
            UpdateProperty(MembershipReviewSiteXSLTEmail.MEMBERSHIPERROR,txtMembershipError.Text);
            UpdateProperty(MembershipReviewSiteXSLTEmail.MEMBERSHIPPENDING,txtMembershipPending.Text);
            UpdateProperty(MembershipReviewSiteXSLTEmail.MEMBERSHIPREJECTED,txtMembershipRejected.Text);
            UpdateProperty(MembershipReviewSiteXSLTEmail.PASSWORDRECOVERY,txtPasswordRecovery.Text);
        }

        private void UpdateProperty(string key, string value)
        {
            if (this.Web.Properties.ContainsKey(key))
            {
                this.Web.Properties[key] = value;
            }
            else
            {
                this.Web.Properties.Add(key, value);
               
            }
            this.Web.Properties.Update();
        }
        
    }
}